﻿using Util.ExtensionMethods;
using SupportLayer.ExtensionMethods;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace DataLayer.BD
{
	public class DataAccess
	{
		public int Insert(object _object, string _idField, string _nomeTabela)
		{
			return new Connection().Insert(_object.toInsertQueryString(_nomeTabela), _idField, _nomeTabela);
		}
		public DataTable Select(object _object, string _nomeTabela, string[] campos, Dictionary<string, object> parametros)
		{
			return new Connection().Select(_object.toSelectQueryString(_nomeTabela, campos, parametros));
		}
		public void Update(object _object, string _nomeTabela, Dictionary<string, object> set, Dictionary<string, object> parametros)
		{
			new Connection().Update(_object.toUpdateQueryString(_nomeTabela, set, parametros));
		}
		public void Delete(string _nomeTabela, string _campoID, Int64 ID)
		{
			new Connection().Delete("delete from " + _nomeTabela + " where " + _campoID + "=" + ID.ToString());
		}

		public Int64 GetIdentity(string _nomeTabela, string _campoID)
		{
			return new Connection().Select("select top 1 * from " + _nomeTabela + " order by " + _campoID + " desc").lastID();
		}
		public Int32 GetNumberOfMatchingRows(object _object, string _nomeTabela, Dictionary<string, object> parametros)
		{
			return Convert.ToInt32(new Connection().Select(_object.getNumberOfMatchingRows(_nomeTabela, parametros)).Rows[0][0].ToString());
		}
	}
}
